import requests

from basic.base import RequestBase
from config import ENV


class Url:
    _Url_coupon_select = 'adminapi/shop/goods/coupon'
    _Url_coupon_add = 'adminapi/shop/goods/coupon'
    _Url_coupon_edit = 'adminapi/shop/goods/coupon/edit'
    _Url_coupon_invalid = 'adminapi/shop/goods/coupon/invalid'
    _Url_coupon_records = 'adminapi/shop/goods/coupon/detail'

class Marketing(RequestBase,Url):
    def goods_coupon_select(self):
        # 优惠券查询
        return self._get(self.goods_coupon_select.__name__,self._Url_coupon_select)

    def goods_coupon_add(self,title,price):
        # 优惠券添加
        data = {
            "json": {
                'title': title,
                'price': price,
                'type': 1,
                'limit': 2,
                'receive_type': 1,
                'remain_count': 1000,
                'threshold': 2,
                'limit_count': '24',
                'min_condition_money': 1,
                'length': '24',
                'receive_type_time': 2,
                'valid_type': 1,
                'receive_time': [
                    '2025-03-14T12:55:00.248Z',
                    '2025-04-13T12:55:00.248Z',
                ],
                'valid_time': '2025-04-13T12:55:00.248Z',
            },

        }
        return self._post(self.goods_coupon_add.__name__,ENV.HOST + self._Url_coupon_add,data)

    def goods_coupon_edit(self,coupon_id,title,price):
        """优惠券编辑"""
        data = {
            "json": {
                'title': title,
                'price': price,
                'type': 1,
                'limit': 2,
                'receive_type': 1,
                'remain_count': 1000,
                'threshold': 2,
                'limit_count': '2',
                'min_condition_money': '0.00',
                'length': 30,
                'receive_type_time': 2,
                'valid_type': 1,
                'receive_time': [
                    '2025-03-15T01:29:24.858Z',
                    '2025-04-14T01:29:24.858Z',
                ],
                'valid_time': '2025-04-14T01:29:24.858Z',
                'id': coupon_id,
                'start_time': 0,
                'end_time': 0,
                'receive_count': 0,
                'status': 1,
                'create_time': '2025-03-14 21:30:12',
                'valid_start_time': 0,
                'valid_end_time': 0,
                'sort': 0,
                'receive_status': 1,
                'sum_count': '不限量',
                'receive_use_count': 0,
                'receive_expire_count': 0,
            }

        }
        return self._put(self.goods_coupon_edit.__name__,ENV.HOST + self._Url_coupon_edit + f"/{coupon_id}",data['json'])

    def goods_coupon_invalid(self,coupon_id):
        """优惠券关闭"""

        return self._put(self.goods_coupon_invalid.__name__, ENV.HOST + self._Url_coupon_edit+f"/{coupon_id}")

    def goods_coupon_records(self,coupon_id):
        """优惠券领取查询"""
        return self._get(self.goods_coupon_records.__name__, ENV.HOST + self._Url_coupon_records+f"/{coupon_id}")

if __name__ == '__main__':
    obj = Marketing()
    obj.goods_coupon_records(45)
    # obj.goods_coupon_edit(1,'11',111)
